Skip to content

Conversation

patrykstefanski
Copy link

Add checks for missing and duplicated assignments in bounds-attributed groups. This model requires each mutable decl in a group to be assigned exactly once.

rdar://161608243

Add checks for missing and duplicated assignments in bounds-attributed
groups. This model requires each mutable decl in a group to be assigned
exactly once.

rdar://161608243
@patrykstefanski patrykstefanski self-assigned this Oct 18, 2025
@patrykstefanski patrykstefanski added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label Oct 18, 2025
Copy link

@ziqingluo-90 ziqingluo-90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you. Just have one nitpick.

Btw, is checking dependencies between assignments within one assignment group something we planned to do? For example,

void f(int * __counted_by(n) ptr, size_t n) {
  ptr = span.first(n).data();
  n = 42;  // this assignment should happen first
}

const llvm::SmallPtrSetImpl<const ValueDecl *> &Missing,
bool IsRelatedToDecl, ASTContext &Ctx) override {

llvm::SmallString<64> RequiredAssignments = DeclSetToStr(Required);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option could be using notes to list these objects that need to be assigned exactly once. Each Decl per note.
This way, we could make the warning message shorter and less parameterized (this benefits grep-ing warning messages), and provide more information in notes, e.g., adding " ... need to be assigned exactly once." and pointing to their source locations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option could be using notes to list these objects that need to be assigned exactly once. Each Decl per note. This way, we could make the warning message shorter and less parameterized (this benefits grep-ing warning messages), and provide more information in notes, e.g., adding " ... need to be assigned exactly once." and pointing to their source locations.

As agreed, I'll file an issue/rdar and we can come back to this later.

@patrykstefanski
Copy link
Author

@swift-ci test llvm

@patrykstefanski
Copy link
Author

LGTM, thank you. Just have one nitpick.

Btw, is checking dependencies between assignments within one assignment group something we planned to do? For example,

void f(int * __counted_by(n) ptr, size_t n) {
  ptr = span.first(n).data();
  n = 42;  // this assignment should happen first
}

Yes, this is going to be my next part. I already have this in my original PR: #11490

@patrykstefanski patrykstefanski merged commit ef6f833 into swiftlang:next Oct 22, 2025
0 of 2 checks passed
@patrykstefanski patrykstefanski deleted the eng/pstefanski/PR-161608243 branch October 22, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants